package com.jinghua.treatment.wechat.service;

import com.jinghua.treatment.entity.PayHistory;
import com.jinghua.treatment.entity.PayHistoryExample;
import com.jinghua.treatment.mapper.PayHistoryMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PayService {

    @Resource
    private PayHistoryMapper payHistoryMapper;

    public void savePayHistory(PayHistory payHistory){
        payHistoryMapper.insertSelective(payHistory);
    }

    public PayHistory findPayHistoryByOrderId(String wcPayId){
        PayHistoryExample payHistoryExample  = new PayHistoryExample();
        PayHistoryExample.Criteria payHistoryCriteria = payHistoryExample.createCriteria();
        payHistoryCriteria.andWcOrderIdEqualTo(wcPayId);
        List<PayHistory> results = payHistoryMapper.selectByExample(payHistoryExample);
        return results==null?null:results.get(0);
    }

    public void updatePayHistoryByEample(PayHistory payHistory){
        payHistoryMapper.updateByPrimaryKeySelective(payHistory);
    }
}
